package 算法

import scala.annotation.tailrec

object 证书翻转 {
  def main(args: Array[String]): Unit = {

    val solution = Solution
    val i = solution.reverse(-1100000)
    println(
      i
    )
  }

  object Solution {
    def reverse(x: Int): Int = {

      @tailrec
      def first(x: Int): Int = {
        val i = x % 10
        if (i != 0) x
        else first(x / 10)
      }

      val i = first(x)
      if (i < 0) {
        val str = "-" + (i + "").reverse
        val str1 = str.substring(0, str.length - 1)
        str1.toInt

      } else {
        val str = (i + "").reverse
        str.toInt
      }
    }
  }

}
